Public Class TraceRoutedEventButton
    Inherits Button

    Public Shared ReadOnly PreviewGenerateTraceRoutedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("PreviewGenerateTrace", RoutingStrategy.Tunnel, GetType(RoutedEventHandler), GetType(TraceRoutedEventButton))
    Public Shared ReadOnly GenerateTraceRoutedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("GenerateTrace", RoutingStrategy.Bubble, GetType(RoutedEventHandler), GetType(TraceRoutedEventButton))

    Public Event GenerateTraceCompleted(ByVal sender As Object, ByVal e As EventArgs)

    Public Custom Event PreviewGenerateTrace As RoutedEventHandler
        AddHandler(ByVal value As RoutedEventHandler)
            Me.AddHandler(TraceRoutedEventButton.PreviewGenerateTraceRoutedEvent, value)
        End AddHandler

        RemoveHandler(ByVal value As RoutedEventHandler)
            Me.RemoveHandler(TraceRoutedEventButton.PreviewGenerateTraceRoutedEvent, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.RaiseEvent(e)
        End RaiseEvent
    End Event

    Public Custom Event GenerateTrace As RoutedEventHandler
        AddHandler(ByVal value As RoutedEventHandler)
            Me.AddHandler(TraceRoutedEventButton.GenerateTraceRoutedEvent, value)
        End AddHandler

        RemoveHandler(ByVal value As RoutedEventHandler)
            Me.RemoveHandler(TraceRoutedEventButton.GenerateTraceRoutedEvent, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.RaiseEvent(e)
        End RaiseEvent
    End Event

    Protected Overrides Sub OnClick()
        MyBase.OnClick()

        Dim args As New RoutedEventArgs(TraceRoutedEventButton.PreviewGenerateTraceRoutedEvent, Me)
        Me.RaiseEvent(args)

        If args.Handled = False Then
            RaiseEvent GenerateTrace(Me, New RoutedEventArgs(TraceRoutedEventButton.GenerateTraceRoutedEvent, Me))
        End If

        RaiseEvent GenerateTraceCompleted(Me, New EventArgs)

    End Sub

End Class
